import win32gui,win32com.client
def get_hwnd_dic(hwnd, hwnd_title):
    if (win32gui.IsWindow(hwnd)
            and win32gui.IsWindowEnabled(hwnd)
            and win32gui.IsWindowVisible(hwnd)
            and win32gui.GetWindowText(hwnd)):
        hwnd_title[f"{hwnd}"] = win32gui.GetWindowText(hwnd)
def get_hwnd():
    """
    :return: {hwnd:title}
    """
    hwnd_title = {}
    win32gui.EnumWindows(get_hwnd_dic, hwnd_title)
    return hwnd_title
#获取所有窗口句柄
hwndJson = get_hwnd()
print(hwndJson)
